// pages/mine/message/index.js
var request = require("../../../utils/request.js");
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentIndex: 0,
    unreadMessage:[],
    readMessage: [],
    systemMessage: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.init();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //点击事件
  setTab(e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    console.log(id);
    this.setData({
      'currentIndex': id
    });
  },

  swiperChange(e) {
    var that = this;
    var id = e.detail.current;
    this.setData({
      'currentIndex': id
    });
  },
  init:function(){
    this.unRead();
    this.read();
    this.system();
  },
  //未读消息
  unRead:function(){
    var that = this;
    request.request("api/Message/GetMessageList_NotReady", { customerId: app.globalData.userInfo['ID'] }).then(function (res) {
      console.log(res);
      if(res.data.status == 1){
        that.setData({
          "unreadMessage":res.data.data
        })
      }
    })
  },
  //已读消息
  read: function () {
    var that = this;
    request.request("api/Message/GetMessageList_NotReady", { customerId: app.globalData.userInfo['ID'] }).then(function (res) {
      if (res.data.status == 1) {
        that.setData({
          "readMessage": res.data.data
        })
      }
    })
  },
  //系统消息
  system: function () {
    var that = this;
    request.request("api/Message/GetMessageList_System", { customerId: app.globalData.userInfo['ID'] }).then(function (res) {
      if (res.data.status == 1) {
        that.setData({
          "systemMessage": res.data.data
        })
      }
    })
  }
})